import React from "react";
import { useState } from "react";
import { useEffect } from "react";

export default function Useffect() {
  let [count, setcount] = useState(1);

  let addcount = () => {
    setcount(count + 1);
  };

  //   useEffect(() => {
  //     console.log(count++);
  //     console.log("学习useEffect!");
  //   });

  // 只模拟 componentDidMount
  //   useEffect(() => {
  //     console.log("只模拟componentDidMount");
  //   }, []);

  useEffect(() => {
    console.log("只模拟componentDidMount");
  }, [count]);

  useEffect(() => {
    return () => {
      console.log("只模拟componentWillUnmount");
    };
  }, []);
  return (
    <>
      <h1>学习 Useffect 123</h1>
      <h2>{count}</h2>
      <button onClick={addcount}>点击增加</button>
    </>
  );
}
